package com.modbus.tcp.controller;
import java.util.List;

import com.modbus.tcp.utils.ApiReturnObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.modbus.tcp.domain.Positionsensor;
import com.modbus.tcp.service.IPositionsensorService;


/**
 * 安装位置传感器 信息操作处理
 *
 * @author d
 * @date 2024-01-13
 */
@RestController
@RequestMapping("/positionsensor")
public class PositionsensorController   {

    @Autowired
    private IPositionsensorService positionsensorService;

    /**
     * 查询安装位置传感器列表
     */
    @GetMapping("/list")
    public ApiReturnObject list(Positionsensor positionsensor,Integer pageNum,Integer pageSize) {
        if(pageNum != null && pageSize !=null ){
            PageHelper.startPage(pageNum,pageSize);
        }
        List<Positionsensor> list = positionsensorService.selectPositionsensorList(positionsensor);
        PageInfo pageInfo = new PageInfo<>(list);
        return new ApiReturnObject("200","查询成功",pageInfo);
    }


    /**
     * 新增保存安装位置传感器
     */

    @PostMapping("/add")
    public ApiReturnObject addSave(@RequestBody Positionsensor positionsensor) {
        positionsensorService.insertPositionsensor(positionsensor);
        return new ApiReturnObject("200","添加成功","");
    }


    /**
    * 详情安装位置传感器
    */
    @GetMapping("/selectOne")
    public ApiReturnObject selectOne(Integer id){
        Positionsensor result = positionsensorService.selectPositionsensorById(id);
        return new ApiReturnObject("200","查询成功",result);
    }
    @GetMapping("/selectSensorbyposition")
    public ApiReturnObject selectSensorbyposition(Integer id,Integer partcode){
        List<Positionsensor> list = positionsensorService.selectSensorbyposition(id,partcode);
        return new ApiReturnObject("200","查询成功",list);
    }

    /**
     * 修改保存安装位置传感器
     */

    @PostMapping("/update")
    public ApiReturnObject editSave(@RequestBody Positionsensor positionsensor) {
        positionsensorService.updatePositionsensor(positionsensor);
        return new ApiReturnObject("200","修改成功","");
    }

    /**
     * 删除安装位置传感器
     */

    @PostMapping("/del")
    public ApiReturnObject remove(String ids) {
        positionsensorService.deletePositionsensorByIds(ids);
        return new ApiReturnObject("200","删除成功","");
    }
}